package com.oa.ylms.apps.dao.assess.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.assess.IAssessItemDao;
import com.oa.ylms.apps.entity.assess.AssessItemValue;

@SuppressWarnings("unchecked")
public class AssessItemDaoImpl extends HibernateDaoSupport implements
		IAssessItemDao {
	
	public int addAssessItem(AssessItemValue assessItem) throws Exception {
		if (assessItem != null) {
			this.getHibernateTemplate().save(assessItem);
		}
		return assessItem.getItemId();
	}

	public boolean editAssesItem(AssessItemValue assessItem) throws Exception {
		if(assessItem!=null){
		try {
			this.getHibernateTemplate().update(assessItem);
		} catch (Exception e) {
			return false;
		}
		return true;
		}
		return false;
	}

	public List<AssessItemValue> queryAllAssessItem() throws Exception {
		return this.getHibernateTemplate().find(
				"from AssessItemValue aiv where aiv.states= ?", IDEDStates.ENABLE);
	}

	public AssessItemValue queryAssessItemByItemId(int itemId)
			throws Exception {

		return (AssessItemValue) this.getHibernateTemplate().get(
				AssessItemValue.class, itemId);
	}

	public List<AssessItemValue> queryAssessItemByCategoryId(int categoryId)
			throws Exception {
		
		return this.getHibernateTemplate().find("from AssessItemValue aiv where aiv.itemCategory.categoryId =? ", categoryId);
	}


}
